/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>拼团列表</h3>
        <h5>商城拼团列表查询及管理</h5>
      </div>
    </div>

    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>点击查看操作将显示订单（包括订单物品）的详细信息</li>
          <li>点击取消操作可以取消订单（在线支付但未付款的订单和货到付款但未发货的订单）</li>
          <li>如果平台已确认收到买家的付款，但系统支付状态并未变更，可以点击收到货款操作(仅限于下单后7日内可更改收款状态)，并填写相关信息后更改订单支付状态</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>

    <div class="mDiv">
      <div class="ftitle">
        <h3>拼团列表</h3>
        <h5>(共 {{page.total}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-select v-model="query.status" placeholder="拼团状态" clearable size="small">
          <el-option
            v-for="item in statusArr"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-date-picker
          size="small"
          v-model="dateRange"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="下单日期起始"
          end-placeholder="下单日期截止"
          :picker-options="pickerOptions"
        ></el-date-picker>
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox">
      <el-table :data="page.records" style="width: 100%">
        <el-table-column label="订单编号" prop="order.order_sn" width="140"></el-table-column>
        <el-table-column label="收货人" width="200" show-overflow-tooltip>
          <template slot-scope="scope">{{scope.row.order.consignee}}:{{scope.row.order.mobile}}</template>
        </el-table-column>
        <el-table-column label="总金额" prop="order.goods_price" width="90"></el-table-column>
        <el-table-column label="应付金额" prop="order.order_amount" width="90"></el-table-column>
        <el-table-column label="拼团状态" :formatter="statusFormat" width="90"></el-table-column>
        <el-table-column label="订单状态" prop="order.order_status_detail" width="90"></el-table-column>
        <el-table-column label="支付状态" prop="order.pay_status_detail" width="90"></el-table-column>
        <el-table-column label="发货状态" prop="order.shipping_status_detail" width="90"></el-table-column>
        <el-table-column label="支付方式" prop="order.pay_name" width="90"></el-table-column>
        <el-table-column label="配送方式" prop="order.shipping_name" width="90"></el-table-column>
        <el-table-column label="下单时间" width="200">
          <template slot-scope="scope">{{scope.row.order.add_time | datefmtAll}}</template>
        </el-table-column>
        <el-table-column label="店铺" prop="store.store_name" width="200"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button
                size="small"
                @click="orderDetail(scope.row.order.order_sn)"
                icon="el-icon-document"
              >订单详情</el-button>
              <el-button
                size="small"
                @click="toTeamOrder(scope.row.order.prom_id)"
                icon="el-icon-s-order"
              >查看拼单</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getTeamFoundOrderPage } from "@/utils/api";
export default {
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      dateRange: "",
      statusArr: [
        {
          value: 1,
          label: "待成团"
        },
        {
          value: 2,
          label: "已成团"
        },
        {
          value: 3,
          label: "未成团"
        }
      ],
      query: {},
      page: {
        total: 0
      },
      currentPage: this.$route.params.currentPage || 1,
      pageSize: 10
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      that.query.p = that.currentPage;
      that.query.size = that.pageSize;
      if (this.dateRange != null && this.dateRange.length > 1) {
        this.query.found_time_start = parseInt(
          this.dateRange[0].valueOf() / 1000
        );
        this.query.found_time_end = parseInt(
          this.dateRange[1].valueOf() / 1000
        );
      } else {
        this.$delete(this.query, "found_time_start");
        this.$delete(this.query, "found_time_end");
      }
      getTeamFoundOrderPage(that.query).then(function(res) {
        that.page = res;
      });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    },
    orderDetail(orderSn) {
      this.$router.push({
        name: "order_detail",
        params: {
          sn: orderSn,
          currentPage: this.currentPage
        }
      });
    },
    toTeamOrder(promId) {
      this.$router.push({
        name: "team_found",
        params: {
          found_id: promId,
          currentPage: this.currentPage
        }
      });
    },
    statusFormat(row, column) {
      if (row.status == 0) {
        return "待开团";
      }
      if (row.status == 1) {
        return "已开团";
      }
      if (row.status == 2) {
        return "拼团成功";
      }
      if (row.status == 3) {
        return "拼团失败";
      }
      return "无状态";
    }
  }
};
</script>

<style scoped>
</style>
